class Solution {
public:
    bool isPrime(int n)
    {
        if(n<=1) return false;
        for(int i=2;i<=n/i;++i)
        {
            if(n%i==0) return false;
        }
        return true;
    }

    int primePalindrome(int n) {
        if(n<=11)
        {
            int num=n;
            while(!isPrime(num)) ++num;
            return num;
        }
        int left=10;
        while(1)
        {
            int palindrome=generatePalindrome(left);
            if(palindrome>=n&&isPrime(palindrome))
                return palindrome;
            ++left;
        }
        return 0;
    }

    int generatePalindrome(int left)
    {
        int palindrome=left;
        left/=10;
        while(left>0)
        {
            palindrome=palindrome*10+left%10;
            left/=10;
        }
        return palindrome;
    }
};
